home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: What should be returned?
- Date: Wed, 17 Jan 1996 21:30:31 GMT
- Organization: Netcom
- Message-ID: <30fd5c1a.5495936@nntp.ix.netcom.com>
- References: <4dj8pv$cjd@eng_ser1.erg.cuhk.hk>
- NNTP-Posting-Host: ix-dc8-02.ix.netcom.com
- X-NETCOM-Date: Wed Jan 17 1:30:29 PM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- phsung@cs.cuhk.hk (the CAReLess boy) wrote:
-
- |>Hi, all,
- |>
- |> It's said that the function main must return an integer value
- |>but I just don't know what value should be returned. Also, if I
- quit
- |>main by exit(), what's the use of the return value?
- |>
- |> Any help?
-
- If you always use exit() from main, you need not have a return
- statement. For example, the following is legal:
-
- #include <stdlib.h>
- int main(void)
- {
- exit(0);
- }
-
- In fact, it's even legal to have neither a return or exit():
-
- int main(void)
- {
- }
-
- This will return an undefined value to the operating environment, but
- does not result in undefined behavior and will not do damage. I
- strongly recommend against this practice and many compilers will issue
- a warning message.
-
- What is not legal is to define main as returning a type other than
- int. The above would be illegal if main were defined as void
- main(void). Defining main as returing anything but int results in
- undefined behavior; the standard allows the compiler to do anything
- (format your disk, send email to your boss complaining about your
- incompetence, ...).
-
-
- Michael M Rubenstein
-